package org.ajc.gift.controller;


import org.ajc.gift.service.IVerifyCodeService;
import org.ajc.gift.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 发送和验证码的Controller
 */
@RestController
@RequestMapping("/user/verifyCode")
public class VerifyCodeController {


    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 发送验证码给用户
     * @param phone
     * @return
     */
    @GetMapping("/register/sendSms/{phone}")
    public AjaxResult registerSendSms(@PathVariable("phone") String phone){
        try {
            verifyCodeService.registerSendSms(phone);
            return AjaxResult.me().setCode(200);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("发送验证码失败！");
        }
    }

}
